<extend name="layout/main" />

<block name="header">
   <style type="text/css">
        .xw-searchQuery{ display: none; }
        .xw-form .xw-btnRow{
            text-align: left !important;
            padding-left: 180px !important;
            background: none; 
            border: none;
        }
   </style>
</block>

<block name="content">
    <div class="wrapper">
		<div class="panel-heading">
			<control:search id="searchs" />
		</div>
		<div class="content" style="height: 200px;">
			<div style="height: 100%;width:calc(100% - 400px);float: left;">
				<control:Form id="form"/>
			</div>
		</div>
	</div>
</block>


<block name="js">
   <script type="text/javascript">
    var  page = (function(ns){
        
        //页面初始化
        ns.init=function(){
			ns.query();
        }
        
        //搜索事件
		ns.query = function() {
			// var shop_id = searchs.getData()[0]['value'];
			// $("#iframe").attr('src','/modules/analysis/keyAcountChase/edit?mode=2&oid='+shop_id);
            var data = searchs.getData()
			var params = {}
            data.forEach(function (item) {
                if( item.type == 'date' ){
                    if( params[item.field] != undefined ){
                        params[item.field] += (' - ' + item.value)
                    }else{
                        params[item.field] = item.value
                    }
                }else{
                    params[item.field] = item.value
                }
                // date
            })
            $.ajaxs('/admin/v2/key_chase/get', params).then(function (res) {
                if( res.data ){
                    var data = JSON.parse(res.data)
                    form.setFormValue(data);         
                }else{
                    form.clearData()               
                }
            })
		}
   
        ns.save=function(){
            var params = {}
            params['shop_id'] = searchs.getData()[0].value
            var data = form.getData()
            params['data'] = JSON.stringify(data)
            $.ajaxs('/admin/v2/key_chase/set', params).then(function (res) {
                $.toast(1, '保存成功')
            })
        }

        return ns;
    }({}));
    
    //加载当前页面需要的控件和配置
    $(function(){  page.init();  });
   </script>
</block>


